<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            注意，是任意两个节点。二叉搜索树的特性就是中序遍历后，可以得到
            一个递增的序列。只需要计算相邻两元素的最小差值即可
            */
            var getMinimumDifference = function (root) {
                let res = []
                function inOrder(root) {
                    if (!root) return null
                    inOrder(root.left)
                    res.push(root.val)
                    inOrder(root.right)
                }
                inOrder(root)
                let min = Infinity
                for (let i = 1; i < res.length; i++) {
                    let cha = Math.abs(res[i] - res[i - 1])
                    if (min >= cha) {
                        min = cha
                    }
                }
                return min
            }
        </script>
    </body>
</html>
